/**
  ******************************************************************************
  * @file    iap_flash.h 
  * @author  iron
  * @date 	 2018-07-09
  * @version v1.0
  * @brief   iap_flash header file
  */

#ifndef __IAP_FLASH_H
#define __IAP_FLASH_H

#ifdef __cplusplus
 extern "C" {
#endif 

/* includes -------------------------------------------------------------------*/
#include <stdint.h>

/* exported defines ------------------------------------------------------------*/

/* Applicaiton start address */
#define APP_FLASH_START_ADDRESS 						0x8020000	// 128K
#define APP_FLASH_END_ADDRESS        				0x80FFFFF
//																					0x8100000

/* Define the user application size */
#define APP_FLASH_SIZE   (APP_FLASH_END_ADDRESS - APP_FLASH_START_ADDRESS + 1)	// default: 896/2  448K

/* exported types ------------------------------------------------------------*/
/* exported constants --------------------------------------------------------*/
/* exported macro ------------------------------------------------------------*/
/* Error code */
enum 
{
  FLASHIF_OK = 0,
  FLASHIF_ERASEKO,
  FLASHIF_WRITINGCTRL_ERROR,
  FLASHIF_WRITING_ERROR
};
  
enum{
  FLASHIF_PROTECTION_NONE         = 0,
  FLASHIF_PROTECTION_PCROPENABLED = 0x1,
  FLASHIF_PROTECTION_WRPENABLED   = 0x2,
  FLASHIF_PROTECTION_RDPENABLED   = 0x4,
};

/* exported functions ------------------------------------------------------- */
uint32_t iap_flash_erase(uint32_t StartSector);
uint32_t iap_flash_write(uint32_t FlashAddress, uint32_t* Data ,uint32_t DataLength);
uint16_t iap_flash_get_write_protection_status(void);
int ipa_flash_write_protection_config(uint32_t modifier);

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif /* __IAP_FLASH_H */

/*******************(C)COPYRIGHT 2018 Iron *****END OF FILE*******************/
